use chrono::Local;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct MessageResp<T> {
    pub event: String,
    pub from: String,
    pub to: String,
    pub data: T,
}

#[derive(Serialize, Deserialize)]
pub struct SystemResp<T> {
    pub event: String,
    pub kind: String,
    pub data: Vec<T>,
    pub number: usize,
}

/// 连接ID
pub type ConnId = usize;

/// 房间ID
pub type RoomId = String;

/// 消息内容
pub type Msg = String;

/// 客户端自定义用户信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnUser {
    pub conn_id: usize,
    pub name: String,
    pub conn_time: String,
}

impl ConnUser {
    pub fn new(conn_id: ConnId) -> ConnUser {
        let fmt = "%Y-%m-%d %H:%M:%S";
        let now = Local::now().format(fmt);
        ConnUser {
            conn_id,
            name: conn_id.to_string(),
            conn_time: now.to_string(),
        }
    }
}
